package com.imooc.course.server.exception;

import com.imooc.course.server.enums.BusinessExceptionEnum;

public class BusinessException extends RuntimeException {


    private BusinessExceptionEnum code;

    public BusinessException(BusinessExceptionEnum code) {
        super(code.getDesc());
        this.code = code;
    }

    /**
     * 父类的fillInStackTrace方法是用于填充堆栈信息
     * 因为这个是业务异常，不是程序错误，所以为了提高性能，不填充堆栈信息。
     * 不填充堆栈信息，也就不需要synchronized
     * @return Throwable
     */
    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

    public BusinessExceptionEnum getCode() {
        return code;
    }

    public void setCode(BusinessExceptionEnum code) {
        this.code = code;
    }
}
